#include <Game/GameExitState.h>

namespace pp
{
    const ne::real GameExitState::EXIT_TIME = 2.0f;

    GameExitState::GameExitState(Game *pContent)
        : GameState(pContent, GAME_EXIT_STATE_ID),
          mTimer(0)
    {
    }

    void GameExitState::onReset()
    {
        mTimer = 0;
    }

    uint32_t GameExitState::onTick(const ne::real interval)
    {
        mTimer += interval;
        if (mTimer < 1.0f)
        {
            mpContent->getMainWindow()->setBackgroundColor(
                ne::Color::Lerp(ne::Color::DARK,
                                ne::Color::WHITE,
                                mTimer));
        }
        else if (mTimer < 2.0f)
        {
            mpContent->getMainWindow()->setBackgroundColor(
                ne::Color::Lerp(ne::Color::WHITE,
                                ne::Color::BLACK,
                                mTimer - 1.0f));
        }
        else
        {
            mpContent->getMainWindow()->setBackgroundColor(ne::Color::DARK);
        }
        if (mTimer >= EXIT_TIME)
        {
            mpContent->requestExit(0);
        }

        return mID;
    }

    GameExitState::~GameExitState()
    {
    }
}
